package chat.client;

import javax.swing.JFrame;
import javax.swing.plaf.metal.*;
import javax.swing.SwingUtilities;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.plaf.*;
import chat.ui.GroupChatWindow;


public class ChatRun {
	
	final static String LOOKANDFEEL = "Nimbus";
	final static String THEME = "Ocean";
	
	 private static void initLookAndFeel() {
	        String lookAndFeel = null;
	       
	        if (LOOKANDFEEL != null) {
	            if (LOOKANDFEEL.equals("Metal")) {
	                lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
	              //  an alternative way to set the Metal L&F is to replace the 
	              // previous line with:
	              // lookAndFeel = "javax.swing.plaf.metal.MetalLookAndFeel";
	                
	            }
	            
	            else if (LOOKANDFEEL.equals("System")) {
	                lookAndFeel = UIManager.getSystemLookAndFeelClassName();
	            } 
	            
	            else if (LOOKANDFEEL.equals("Motif")) {
	                lookAndFeel = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
	            } 
	            
	            else if (LOOKANDFEEL.equals("GTK")) { 
	                lookAndFeel = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
	            } 
	            else if (LOOKANDFEEL.equals("Nimbus")) { 
	                lookAndFeel = "javax.swing.plaf.nimbus.NimbusLookAndFeel";
	            }
	            
	            else {
	                System.err.println("Unexpected value of LOOKANDFEEL specified: "
	                                   + LOOKANDFEEL);
	                lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
	            }
	            
	            try {
	            	
	            	
	                UIManager.setLookAndFeel(lookAndFeel);
	                
	                // If L&F = "Metal", set the theme
	                
	                if (LOOKANDFEEL.equals("Metal")) {
	                  if (THEME.equals("DefaultMetal"))
	                     MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
	                  else if (THEME.equals("Ocean"))
	                     MetalLookAndFeel.setCurrentTheme(new OceanTheme());
	                  else
	                     //MetalLookAndFeel.setCurrentTheme(new TestTheme());
	                	  //MetalLookAndFeel.setCurrentTheme(new OceanTheme());
	                  
	                  UIManager.setLookAndFeel(new MetalLookAndFeel()); 
	                }	
	                	
	                	
	                  
	                
	            } 
	            
	            catch (ClassNotFoundException e) {
	                System.err.println("Couldn't find class for specified look and feel:"
	                                   + lookAndFeel);
	                System.err.println("Did you include the L&F library in the class path?");
	                System.err.println("Using the default look and feel.");
	            } 
	            
	            catch (UnsupportedLookAndFeelException e) {
	                System.err.println("Can't use the specified look and feel ("
	                                   + lookAndFeel
	                                   + ") on this platform.");
	                System.err.println("Using the default look and feel.");
	            } 
	            
	            catch (Exception e) {
	                System.err.println("Couldn't get specified look and feel ("
	                                   + lookAndFeel
	                                   + "), for some reason.");
	                System.err.println("Using the default look and feel.");
	                e.printStackTrace();
	            }
	        }
	    }
	
	 public static void main (String [] args) throws Exception{
			
		 	SwingUtilities.invokeLater(new Runnable() {
		 
		 	public void run() {
		 		
		 	GroupChatWindow chat;
			try {
				
				JFrame.setDefaultLookAndFeelDecorated(true);
				JDialog.setDefaultLookAndFeelDecorated(true);
				initLookAndFeel();
				chat = new GroupChatWindow();
				chat.setResizable(true);
				chat.pack();
				chat.setSize(new Dimension(800,600));
				chat.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			} catch (Exception e) {
				e.printStackTrace();
			}		
		 	}
		 	});
		}
}
